﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BOL;
using System.Data.Linq;
using System.Data.SqlClient;
using Website.Logger;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.DataVisualization.Charting;
using ExtAspNet;
using System.Web.UI.DataVisualization.Charting;


namespace UILGestion.ObraAdmin
{
    public partial class ObraAdminForm : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.IsPostBack)
                {
                    idObra.Value = (string)Request.QueryString["idObra"];

                    menuObraCtrl1.loadMenu(int.Parse(idObra.Value), Request.AppRelativeCurrentExecutionFilePath);
                    FormatForm();
                }

             
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }

        }

        private void FormatForm()
        {
         
            ListValueBL bol= new ListValueBL();

            //AlamacenesDropDownList.DataSource=bol.GetAlmacenes(int.Parse(idObra.Value));
            //AlamacenesDropDownList.DataValueField = "idInternal";
            //AlamacenesDropDownList.DataTextField="descripcion";
            //AlamacenesDropDownList.DataBind();

            PanelComprativo.Visible = false;
            OrdenCompraPAprobPanel.Visible = false;
           // OrdenCompraPendienteRecepPanel.Visible = false;
            OrdenCompraPendRecepDocumentoPanel.Visible = false;

            // segun rol
            int i=(int)Session["idEmpleado"];
            Rol rol=new Rol();
            var q = from a in DbUtil.Db.EmpleadoObras
                    where a.idEmpleado == i
                    & a.idObra == int.Parse(idObra.Value)
                    select a.Rol;
            if (q.Count()>0)
            {
                rol = q.First();
            }
            

           //if(rol.nivelComparativo==2)
           //{
                PanelComprativo.Visible = true;

            //OrdenCompraPAprobPanel.Visible = false;
            //OrdenCompraPendienteRecepPanel.Visible = false;
            //OrdenCompraPendRecepDocumentoPanel.Visible = false;
           //}
           //if (rol.bitAprobarOrdenCompra)
           //{
               OrdenCompraPAprobPanel.Visible = true;
               //OrdenCompraPendienteRecepPanel.Visible = false;
               //OrdenCompraPendRecepDocumentoPanel.Visible = false;
           //}

            //OrdenCompraPendienteRecepPanel.Visible = true;
            OrdenCompraPendRecepDocumentoPanel.Visible = true;

            Obra001Chart1.LoadChart(int.Parse(idObra.Value));
            Obra002Chart1.LoadChart(int.Parse(idObra.Value));

            Cuota003Chart1.LoadChart(int.Parse(idObra.Value));
           
            //BOL.ComparativoBL Comparativo= new BOL.ComparativoBL();
            //BOL.OrdenCompraBL ordenCompra= new OrdenCompraBL();


            //var q=Comparativo.getComparativoPendienteList(int.Parse(idObra.Value));

            //    comparativoPorAprobGridView.DataSource = q;
            //    comparativoPorAprobGridView.DataBind();

            //var w= ordenCompra.getOrdenCompraSinFactura(int.Parse(idObra.Value));


            //OrdenCompraGridView.DataSource = w;
            //OrdenCompraGridView.DataBind();




            //using (dbGestionDataContext _db = new dbGestionDataContext())
            //{
            //    var qq = from a in _db.EstructuraCostos
            //             where a.idObra== int.Parse(idObra.Value)
            //             select new
            //             {
            //                 x = a.descripcion,
            //                 y = a.monto
            //             };



            //    Chart1.Series["Series 1"].Points.DataBindXY(qq.ToList(), "y", qq.ToList(), "X");
            //}


            ////carga de grafico
            //// Set series font
            
            //Chart1.Series[0].Font = new Font("Trebuchet MS", 8, FontStyle.Bold);

            //Chart1.Series[0]["CollectedToolTip"] = "Other";

            //Series series1 = Chart1.Series[0];



            //// Set the threshold under which all points will be collected
            //series1["CollectedThreshold"] = "5";

            //// Set the label of the collected pie slice
            //series1["CollectedLabel"] = "true";

            //// Set the legend text of the collected pie slice
            //series1["CollectedLegendText"] = "Otros";

            //// Set the collected pie slice to be exploded
            //series1["CollectedSliceExploded"] = "True";

            //// Set collected color
            //series1["CollectedColor"] = "Green";

            //// Set chart type
            //series1.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), "Pie", true);


           
        }

        /// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		

		public void UpdateChartSettings()
		{			
		}


        protected void Grid2_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Alert.ShowInParent(e.NewPageIndex.ToString());
        }

        protected void Grid2_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
            Alert.ShowInParent(e.SortField);

        }
    }
}
